
$(".gotop").on("click", function () {
    $("html,body").animate({ // 让body和html回到顶部
        scrollTop: 0
    }, 500)
})

$(".icon-xialajiantou").click(function () {
    let index = $(this).index(".icon-xialajiantou");
    $(this).style.transform = "rotate(180deg)";
    $(".selector-tag").eq(index).style.display = "block";
    $(".selector-tag").eq(index).siblings("selector-tag").style.display = "none";
})




//================================================
$(function () {
    getAllType();
    getGoodsList()
    getGoodsList1()
    getGoodsList2()
    getGoodsList3()
    getId()
})
function getAllType() {
    $.get('../goodsAndShoppingCart/getGoodsType.php', function (data) {
        data.forEach(function (item, index) {
            $(".chanpin>h2").eq(index).html(item.goodsType)
        })
    }, "json")
}
function getGoodsList() {
    $.get('../goodsAndShoppingCart/getGoodsList.php', { "typeId": "001" }, function (data) {
        str = '';

        data.forEach(function (item, index) {
            console.log(data);
            str += `
            <li goodsid="${item.goodsId}">
                            <a href="javascript:;">
                                <img src="${item.goodsImg}" alt="">
                                <div class="jieshi">${item.goodsName}</div>
                                <div class="jieshi">${item.goodsDesc}</div>
                                <div class="price">${item.goodsPrice}</div>
                            </a>

                        </li>
            `
        })
        $(".chanpin>ul").eq(0).html(str)
    }, "json")
}
function getGoodsList1() {
    $.get('../goodsAndShoppingCart/getGoodsList.php', { "typeId": "002" }, function (data) {
        str = '';

        data.forEach(function (item, index) {
            console.log(data);
            str += `
            <li goodsid="${item.goodsId}">
                            <a href="javascript:;">
                                <img src="${item.goodsImg}" alt="">
                                <div class="jieshi">${item.goodsName}</div>
                                <div class="jieshi">${item.goodsDesc}</div>
                                <div class="price">${item.goodsPrice}</div>
                            </a>

                        </li>
            `
        })
        $(".chanpin>ul").eq(1).html(str)
    }, "json")
}
function getGoodsList2() {
    $.get('../goodsAndShoppingCart/getGoodsList.php', { "typeId": "003" }, function (data) {
        str = '';

        data.forEach(function (item, index) {
            console.log(data);
            str += `
            <li goodsid="${item.goodsId}">
                            <a href="javascript:;">
                                <img src="${item.goodsImg}" alt="">
                                <div class="jieshi">${item.goodsName}</div>
                                <div class="jieshi">${item.goodsDesc}</div>
                                <div class="price">${item.goodsPrice}</div>
                            </a>

                        </li>
            `
        })
        $(".chanpin>ul").eq(2).html(str)
    }, "json")
}
function getGoodsList3() {
    $.get('../goodsAndShoppingCart/getGoodsList.php', { "typeId": "004" }, function (data) {
        str = '';

        data.forEach(function (item, index) {
            console.log(data);
            str += `
            <li goodsid="${item.goodsId}">
                            <a href="javascript:;">
                                <img src="${item.goodsImg}" alt="">
                                <div class="jieshi">${item.goodsName}</div>
                                <div class="jieshi">${item.goodsDesc}</div>
                                <div class="price">${item.goodsPrice}</div>
                            </a>

                        </li>
            `
        })
        $(".chanpin>ul").eq(3).html(str)
    }, "json")
}



function getId() {
    $(".chanpin").on('click', 'li', function () {
        let id = $(this).attr("goodsid") || $(this).parent().attr("goodsid")
        location.href = "./xiangqing2.html?goodid=" + id;
    })
}







